package com.yuanfeng.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.business.dto.ManageShopVideoDTO;
import com.yuanfeng.business.entity.ShopVideosEntity;
import com.yuanfeng.business.mapper.ShopVideosMapper;
import com.yuanfeng.business.service.ShopVideosService;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ParseTokenUtils;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.commoms.vo.user.UserInfoVO;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 *
 */
@Service
public class ShopVideosServiceImpl extends ServiceImpl<ShopVideosMapper, ShopVideosEntity>
    implements ShopVideosService{

    @Override
    public ResponseResult updateVideo(ManageShopVideoDTO param) {
        UserInfoVO userInfoVO = ParseTokenUtils.getUserInfoByToken(param.getToken());

        if (userInfoVO != null) {
            param.setShopId(userInfoVO.getShopId());
            param.setUserId(userInfoVO.getUserId());

        } else {
            return ResponseResult.fail(BizCodeEnume.INSUFFICIENT_PERMISSIONS);
        }

        param.setUpdateDate(new Date());
        if (null == param.getVideoId()) {
            this.baseMapper.insertVideo(param);
        } else {
            this.baseMapper.updateVideo(param);
        }
        return ResponseResult.success();
    }
}




